rm(list=ls(all=TRUE))
library(metafor)
library(clubSandwich)
library(dplyr)

setwd("~/Dropbox/Apps/ShareLaTeX/Minimal Effects/replication/data")

data <- read.csv("master_sheet_output.csv", stringsAsFactors = FALSE)
data <- subset(data, !is.na(Turnout.Estimate))

#De-duplicate experiments
table(data$Experiment)
data <- data[!duplicated(data$Experiment),]
data$label <- paste0('Original Study - ', toupper(substr(data$Experiment, 1 ,2)), ' - ', 'Canvass')
data[3, "label"] <- "Original Study - OH Early - Canvass"
data[4, "label"] <- "Original Study - OH Late - Canvass"

#Overall Turnout Effect
data$Turnout.Estimate <- data$Turnout.Estimate * 100
data$Turnout.SE <- data$Turnout.SE * 100
data$Turnout.V <- data$Turnout.SE^2
meta <- rma.mv(yi = Turnout.Estimate, V = Turnout.V, random = list(~1 | Experiment),
               data = data)
pdf('forest_wa_turnout.pdf', width = 10, height = 4)
forest(meta, slab = data$label, cex = .8, xlab = "Estimated Turnout Effect (CACE) in Percentage Points and 95% Confidence Interval")
dev.off()

#Interaction with Basline
data$Turnout.Baseline.Intereaction <- data$Turnout.Baseline.Intereaction * 100
data$Turnout.Baseline.SE <- data$Turnout.Baseline.SE * 100
data$Turnout.Baseline.V <- data$Turnout.Baseline.SE^2
meta <- rma.mv(yi = Turnout.Baseline.Intereaction, V = Turnout.Baseline.V, random = list(~1 | Experiment),
               data = data)
pdf('../figures/forest_wa_turnout_interaction.pdf', width = 10, height = 4)
forest(meta, slab = data$label, cex = .8, xlab = "Estimated Interaction Between Turnout Effect and Baseline Support (CACE) in Percentage Points and 95% Confidence Interval")
dev.off()

